home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / x11windows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  35.5 KB  |  1,231 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      windows
  20.    PURPOSE
  21.      
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Mar 14, 1995: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <proto/intuition.h>
  30. #include <proto/graphics.h>
  31. #include <proto/gadtools.h>
  32.  
  33. #include <dos.h>
  34. #include <signal.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37.  
  38. #include "libX11.h"
  39.  
  40. #define MAX_COORD 200
  41.  
  42. #define XLIB_ILLEGAL_ACCESS 1
  43.  
  44. #include <X11/X.h>
  45. #include <X11/Xlib.h>
  46.  
  47. #include <X11/Xutil.h>
  48. #include <X11/Intrinsic.h>
  49. #include <X11/IntrinsicP.h>
  50. #include <X11/CoreP.h>
  51.  
  52. #include <X11/Xlibint.h>
  53.  
  54. #include <libraries/mui.h>
  55. #include <proto/muimaster.h>
  56.  
  57. #include "amigax_proto.h"
  58. #include "amiga_x.h"
  59.  
  60. #undef memset
  61.  
  62. extern struct IntuitionBase *IntuitionBase;
  63. extern struct GfxBase *GfxBase;
  64. /*extern struct Library *AslBase;*/
  65. extern struct Library *GadToolsBase;
  66. extern struct Library *DiskfontBase;
  67. extern struct Library *LayersBase;
  68. extern struct DosLibrary *DOSBase;
  69.  
  70. extern struct Screen *Scr,*wb;
  71. extern struct RastPort temprp,*drp;
  72. extern GC amiga_gc;
  73. extern int usewb,wbapp,adjx,adjy,borderadj;
  74. extern int X_relx,X_rely,X_bottom,X_right;
  75. extern Window prevwin;
  76. extern GC prevgc;
  77. extern X11userdata *Xuserdata;
  78.  
  79. int XParseGeometry(parsestring, x_return, y_return, width_return,
  80.            height_return)
  81.      char *parsestring;
  82.      int *x_return, *y_return;
  83.      unsigned int *width_return, *height_return;
  84. {
  85.   int n,ret=0;
  86. #ifdef DEBUGXEMUL_ENTRY
  87.   printf("XParseGeometry [%s]\n",parsestring);
  88. #endif
  89.   if(!parsestring) return;
  90.   *x_return=0;
  91.   *y_return=0;
  92.   *width_return=0;
  93.   *height_return=0;
  94.   if(strchr(parsestring,'x')!=0){
  95.     sscanf(parsestring,"%dx%d",width_return,height_return);
  96.     ret=WidthValue|HeightValue;
  97.   }
  98.   if(strchr(parsestring,'+')!=0||strchr(parsestring,'-')!=0){
  99.     ret=ret|XValue|YValue;
  100.     sscanf(parsestring,"%dx%d%d%d",&n,&n,x_return,y_return);
  101.   }
  102.   return(ret);
  103. }
  104.  
  105. int X11windepth=3;
  106.  
  107.  
  108. Window XCreateWindow(display, parent, x, y, width, height,
  109.              border_width, depth, class, visual, valuemask,
  110.              attributes)
  111.      Display *display;
  112.      Window parent;
  113.      int x, y;
  114.      unsigned int width, height;
  115.      unsigned int border_width;
  116.      int depth;
  117.      unsigned int class;
  118.      Visual *visual;
  119.      unsigned long valuemask;
  120.      XSetWindowAttributes *attributes;
  121. {
  122.   int bg=0;
  123. #ifdef DEBUGXEMUL_ENTRY
  124.   printf("XCreateWindow\n");
  125. #endif
  126.   if(attributes) bg=attributes->background_pixel;
  127.   X11windepth=depth;
  128.   return(XCreateSimpleWindow(display,parent,x,y,width,height,border_width,1,bg));
  129. }
  130.  
  131. Window XCreateSimpleWindow(display, parent, x, y, width, height,
  132.                border_width, border, background)
  133.      Display *display;
  134.      Window parent;
  135.      int x, y;
  136.      unsigned int width, height, border_width;
  137.      unsigned long border;
  138.      unsigned long background;
  139. {
  140. /*  struct Window *win;*/
  141.   Window newwin;
  142. #ifdef DEBUGXEMUL_ENTRY
  143.   printf("(display)XCreateSimpleWindow %d %d %d %d\n",x,y,width,height);
  144. #endif
  145.   wbapp=1;
  146.   if(border_width==0) border=0;
  147.   if(!Scr) Scr=wb;
  148.   if(parent==ROOTID){
  149.     if(width>Scr->Width||height>Scr->Height||X11windepth>Scr->RastPort.BitMap->Depth){ 
  150.       int i,nXMax=0,nYMax=0;
  151.       /*asking for a bigger window than wb can handle */
  152.       wbapp=0;
  153.       for(i=0;i<X11NumDrawablesWindows;i++)
  154.     if(X11ActualWindows[i].mapped){
  155.       XUnmapWindow(NULL,X11ActualWindows[i].win);
  156.       if(X11ActualWindows[i].width>nXMax) nXMax=X11ActualWindows[i].width;
  157.       if(X11ActualWindows[i].height>nYMax) nYMax=X11ActualWindows[i].height;
  158.       X11ActualWindows[i].mapped=2;
  159.     }
  160.       if(AmigaCreateWindow(max(width,nXMax),max(height,nYMax),DG.nDisplayDepth,0,0)){
  161.     return(0);
  162.       }
  163.       for(i=0;i<X11NumDrawablesWindows;i++)
  164.     if(X11ActualWindows[i].mapped==2){
  165.       XMapWindow(NULL,X11ActualWindows[i].win);
  166.     }
  167.       wbapp=0;usewb=0;
  168.     }
  169.   }
  170.   else{
  171.     int new=0,i,newid;
  172.     for(i=1;i<=DG.nNumChildren;i++){
  173.       if(X11DrawablesChildren[i].deleted&&i>parent){ /* use this as new window */
  174.     new=i; break;
  175.       }
  176.     }
  177.     if(!new){
  178.       new=++DG.nNumChildren;
  179.       newid=X11NewSubWindow(new);
  180.     } else
  181.       newid=X11OldSubWindow(new);
  182.       
  183.     XSelectInput(display,newid,0xffffff);
  184.     if(X11Drawables[parent]==X11SUBWINDOW){
  185.       X11DrawablesChildren[new].x=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[parent]]].x+x;
  186.       X11DrawablesChildren[new].y=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[parent]]].y+y;
  187.     } else{
  188.       X11DrawablesChildren[new].x=x;
  189.       X11DrawablesChildren[new].y=y;
  190.     }
  191.     X11DrawablesChildren[new].width=width;
  192.     X11DrawablesChildren[new].height=height;
  193.     X11DrawablesChildren[new].border=border;
  194.     X11DrawablesChildren[new].deleted=0;
  195.     X11DrawablesChildren[new].parent=parent;
  196.     X11DrawablesChildren[new].id=newid;
  197.     X11DrawablesMask[newid]=X11DrawablesMask[parent];
  198.     X11DrawablesBackground[newid]=background;
  199.     DG.bSubWins=1;
  200.     return((Window)newid);
  201.   }
  202.   newwin=X11NewWindow(0);
  203.   if(width>wb->Width)width=wb->Width;
  204.   if(height>wb->Height)height=wb->Height;
  205.  
  206. /*  init_backrp(Scr->Width,Scr->Height,Scr->RastPort.BitMap->Depth);*/
  207.  
  208.   X11ActualWindows[X11DrawablesMap[newwin]].x=x;
  209.   X11ActualWindows[X11DrawablesMap[newwin]].y=y;
  210.   X11ActualWindows[X11DrawablesMap[newwin]].width=width;
  211.   X11ActualWindows[X11DrawablesMap[newwin]].height=height;
  212.   X11ActualWindows[X11DrawablesMap[newwin]].win=newwin;
  213.   X11ActualWindows[X11DrawablesMap[newwin]].parent=ROOTID;
  214.   X11ActualWindows[X11DrawablesMap[newwin]].pixmap=0;
  215.   X11DrawablesBackground[newwin]=background;
  216.   /*XCreatePixmap(display,NULL,width,height,8);
  217.   if(!Xuserdata)
  218.     init_area(wb->FirstWindow,100,width,height);*/
  219.   XSelectInput(display,newwin,0xffffff);
  220.   X11init_cmaps();
  221.   return(newwin);
  222. }
  223.  
  224. XDestroyWindow(display, win)
  225.      Display *display;
  226.      Window win;
  227. {/*          File 'grafikk.o'*/
  228. #ifdef DEBUGXEMUL_ENTRY
  229.   printf("(display)XDestroyWindow [%d]\n",(int)win);
  230. #endif
  231.   /*  set(X11App->Root,OM_REMMEMBER,obj);*/
  232.   if(X11Drawables[win]==X11SUBWINDOW){ /* this is a child */
  233.     X11DrawablesChildren[X11DrawablesMap[win]].deleted=1;
  234.     clear_subwin(win,0,0);
  235.   }else{
  236. /*    struct Window *w=X11DrawablesWindows[X11DrawablesMap[win]];*/
  237.     int i;
  238.     if(X11ActualWindows[X11DrawablesMap[win]].mapped)XUnmapWindow(display,win);
  239.     X11DrawablesWindows[X11DrawablesMap[win]]=NULL;
  240.     for(i=0;i<DG.nNumChildren;i++){
  241.       if(X11DrawablesChildren[i].parent==win)
  242.     X11DrawablesChildren[i].deleted=1;
  243.     }
  244.   }
  245.   return(0);
  246. }
  247.  
  248. extern int XSetBackground(Display *,GC,unsigned long);
  249. extern int XSetForeground(Display *,GC,unsigned long);
  250. extern int XDrawRectangle(Display *,Drawable,GC,int,int,unsigned int,unsigned int);
  251.  
  252.  
  253. XMapRaised(display, w)
  254.      Display *display;
  255.      Window w;
  256. {
  257. #ifdef DEBUGXEMUL_ENTRY
  258.   printf("(display)XMapRaised\n");
  259. #endif
  260.   if(X11Drawables[w]==X11SUBWINDOW){
  261.     int child=X11DrawablesSubWindows[X11DrawablesMap[w]];
  262.     XSetForeground(display,amiga_gc,X11DrawablesChildren[child].border);
  263.     XSetBackground(display,amiga_gc,X11DrawablesBackground[child]);
  264.     XClearArea(display,X11findparent(w), /*amiga_gc,*/
  265.            X11DrawablesChildren[child].x,
  266.            X11DrawablesChildren[child].y,
  267.            X11DrawablesChildren[child].width-1,
  268.            X11DrawablesChildren[child].height-1,0);
  269.     XMapWindow(display,w);
  270.   } else if (X11Drawables[w]==X11MUI){
  271.     LONG open;
  272.     Object *mwin=X11DrawablesMUI[X11DrawablesMap[w]];
  273.     set(mwin,MUIA_Window_Open,TRUE);
  274.     get(mwin,MUIA_Window_Open,&open);
  275.     if(!open) return(BadWindow);
  276.     return 0;
  277.   }else {
  278.     XMapWindow(display,w);
  279.     ActivateWindow(X11DrawablesWindows[X11DrawablesMap[w]]);
  280.     EG.nEventDrawable=w;
  281.   }
  282.   X11AddInternalEvent(w,VisibilityNotify,sizeof(XVisibilityEvent));
  283.   X11AddInternal(w,VisibilityNotify,sizeof(XVisibilityEvent));
  284.   return(0);
  285. }
  286.  
  287. XUnmapWindow(display, w)
  288.      Display *display;
  289.      Window w;
  290. {
  291.   int i;
  292. #ifdef DEBUGXEMUL_ENTRY
  293.   printf("(display)XUnmapWindow %d\n",w);
  294. #endif
  295.   prevwin=-1;
  296.   prevgc=(GC)-1;
  297.   if (X11Drawables[w]==X11MUI){
  298.     Object *mwin=X11DrawablesMUI[X11DrawablesMap[w]];
  299.     set(mwin,MUIA_Window_Open,FALSE);
  300.     return 0;
  301.   } 
  302.   if(X11Drawables[w]==X11SUBWINDOW){
  303.     int parent=X11findparent(w);
  304. /*    printf("exposing parent %d\n",parent);*/
  305.     clear_subwin(w,1,X11DrawablesBackground[w]);
  306.     X11AddExpose(parent,X11DrawablesWindows[X11DrawablesMap[parent]]);
  307.     return; /* subwindow */
  308.   }
  309.   if(!X11ActualWindows[X11DrawablesMap[w]].mapped) return;
  310.   X11AddInternalEvent(w,UnmapNotify,sizeof(XUnmapEvent));
  311. /*  X11AddInternal(w,UnmapNotify,sizeof(XUnmapEvent));*/
  312.   unclipWindow(X11DrawablesWindows[X11DrawablesMap[w]]->WLayer);
  313.   CG.pPreviousLayer=NULL;
  314. #if 0
  315.   exit_area(X11DrawablesWindows[X11DrawablesMap[w]]);
  316. #endif
  317.   CloseWindow(X11DrawablesWindows[X11DrawablesMap[w]]);
  318.   X11ActualWindows[X11DrawablesMap[w]].mapped=0;
  319.   EG.fwindowsig=0;
  320.   for(i=0;i<X11NumDrawablesWindows;i++)
  321.     if(X11ActualWindows[i].mapped) EG.fwindowsig|=(1<<X11DrawablesWindows[i]->UserPort->mp_SigBit);
  322.   X11DrawablesWindows[X11DrawablesMap[w]]=NULL;
  323.  
  324.   return(0);
  325. }
  326.  
  327. XMapWindow(d, win)
  328.      Display *d;
  329.      Window win;
  330. {
  331.   extern char *LibX11Info;
  332.   struct Window *Win;
  333.   int i,x,y,width,height,background;
  334.  
  335. #ifdef DEBUGXEMUL_ENTRY
  336.   printf("(display)XMapWindow %d\n",win);
  337. #endif
  338.  
  339.   X11AddInternalEvent(win,MapNotify,sizeof(XMapEvent));
  340.   if (X11Drawables[win]==X11SUBWINDOW) {
  341.     int x,y,w,h;
  342. /*    int parent=X11findparent(w);*/
  343. /*    if(!X11ActualWindows[X11DrawablesMap[parent]].mapped)
  344.       printf("and parent is not mapped..\n");*/
  345.     X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].mapped=1;
  346.     Win=X11DrawablesWindows[X11DrawablesMap[win]];
  347.     drp=setup_win(X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].parent);
  348.     x=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].x-1;
  349.     y=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].y-1;
  350.     w=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].width+2;
  351.     h=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].height+2;
  352.     if(X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].border){
  353.       SetAPen(drp,X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].border);
  354.       Move(drp,X_relx+x,X_rely+y);
  355.       Draw(drp,X_relx+x+w,X_rely+y);
  356.       Draw(drp,X_relx+x+w,X_rely+y+h);
  357.       Draw(drp,X_relx+x,X_rely+y+h);
  358.       Draw(drp,X_relx+x,X_rely+y);
  359.     }
  360.     prevgc=(GC)-1;
  361.     X11AddExpose(win,NULL);
  362.     for(i=1;i<=DG.nNumChildren;i++)
  363.       if(!X11DrawablesChildren[i].deleted&&X11DrawablesChildren[i].parent==win)
  364.     XMapWindow(d,X11DrawablesChildren[i].id);
  365. /*
  366.     X11AddConfigure(w,NULL);
  367. */
  368.     return;
  369.   }
  370.   if(X11ActualWindows[X11DrawablesMap[win]].mapped==1){
  371.     return;
  372. /*    XUnmapWindow(display,w);*/
  373.   }
  374.   {
  375.     int parent=X11findparent(win);
  376.     if(parent!=win && parent!=0 && !X11ActualWindows[X11DrawablesMap[parent]].mapped){
  377.       X11ActualWindows[X11DrawablesMap[win]].mapped=4;
  378.       return;
  379.     }
  380.   }
  381.  
  382.   x=X11ActualWindows[X11DrawablesMap[win]].x;
  383.   y=X11ActualWindows[X11DrawablesMap[win]].y;
  384.   width=X11ActualWindows[X11DrawablesMap[win]].width;
  385.   height=X11ActualWindows[X11DrawablesMap[win]].height;
  386.   background=X11DrawablesBackground[win];
  387.  
  388.   {
  389.   }
  390.   X11ActualWindows[X11DrawablesMap[win]].mapped=1;
  391.   if (!(Win = 
  392.     OpenWindowTags(NULL,
  393.                WA_Left,x,WA_Top,y,
  394.                WA_InnerWidth,width,WA_InnerHeight,height,
  395.                WA_MaxWidth,DG.nDisplayMaxWidth,WA_MaxHeight,DG.nDisplayMaxHeight,
  396.                WA_DetailPen,1,WA_BlockPen,0,
  397.                WA_IDCMP,IDCMP_CHANGEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_ACTIVEWINDOW|
  398.                IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_INACTIVEWINDOW|IDCMP_MOUSEMOVE|
  399.                IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  400.                WA_Flags, WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH
  401.                |WFLG_REPORTMOUSE|WFLG_RMBTRAP,
  402.                WA_ScreenTitle,    "X11",
  403.                WA_CustomScreen, Scr,
  404.                TAG_DONE ))) return(NULL);
  405.   
  406.   if(!X11DrawablesWindows[X11DrawablesMap[win]]){
  407.     adjx=Win->BorderLeft+Win->BorderRight;
  408.     adjy=Win->BorderTop+Win->BorderBottom;
  409.     if(borderadj==0)borderadj=1;
  410.   }
  411.   EG.fwindowsig=0;
  412.   X11DrawablesWindows[X11DrawablesMap[win]]=Win;
  413.   for(i=0;i<X11NumDrawablesWindows;i++)
  414.     if(X11ActualWindows[i].mapped==1) EG.fwindowsig|=(1<<X11DrawablesWindows[i]->UserPort->mp_SigBit);
  415.  
  416. /*
  417.   amiga_screen[0].root=w;
  418. */
  419.   X11DrawablesChildren[0].id=ROOTID;
  420.   if(!Xuserdata)
  421.     init_area(Win,MAX_COORD,Win->Width,Win->Height);
  422.   SetRast(Win->RPort,background);
  423.  
  424. /*
  425.   XCopyArea(display,X11ActualWindows[X11DrawablesMap[w]].pixmap,w,amiga_gc,0,0,width,height,0,0);
  426. */
  427.  
  428.   RefreshWindowFrame(Win);
  429.   SetBackground(background);
  430.  
  431.   X11AddExpose(win,Win);
  432. /*
  433.   X11AddConfigure(w,win);
  434. */
  435.   X11AddInternal(win,VisibilityNotify,sizeof(XVisibilityEvent));
  436.  
  437.   SetWindowTitles(Win,X11ActualWindows[X11DrawablesMap[win]].name,LibX11Info);
  438.  
  439.   for(i=1;i<=DG.nNumChildren;i++)
  440.     if(!X11DrawablesChildren[i].deleted&&X11DrawablesChildren[i].parent==win)
  441.       XMapWindow(d,X11DrawablesChildren[i].id);
  442.   return(0);
  443. }
  444.  
  445. XStoreName(display,w,window_name)
  446.      Display *display;
  447.      Window w;
  448.      char *window_name;
  449. {
  450.   struct Window *win;
  451. #ifdef DEBUGXEMUL_ENTRY
  452.   printf("XStoreName [%s]\n",window_name);
  453. #endif
  454.   if(X11Drawables[w]!=X11WINDOW) return; /* not window */
  455.   X11ActualWindows[X11DrawablesMap[w]].name=window_name;
  456.   if(X11ActualWindows[X11DrawablesMap[w]].mapped){
  457.     win=X11DrawablesWindows[X11DrawablesMap[w]];
  458.     SetWindowTitles(win,X11ActualWindows[X11DrawablesMap[w]].name,LibX11Info);
  459.   }
  460.   return(0);
  461. }
  462.  
  463. XResizeWindow(display, win, width, height)
  464.      Display *display;
  465.      Window win;
  466.      unsigned int width, height;
  467. {
  468.   struct Window *w;
  469. #ifdef DEBUGXEMUL_ENTRY
  470.   printf("XResizeWindow to [%d,%d]\n",width,height);
  471. #endif
  472.   X11AddExpose(win,NULL);
  473.   if(X11Drawables[win]==X11SUBWINDOW){
  474.     X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].width=width;
  475.     X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[win]]].height=height;
  476.     return;
  477.   }
  478.   if(X11Drawables[win]==X11BITMAP) {
  479. #ifdef DEBUGX11BITMAP
  480.     printf("resize bitmap with XResizeWindow?\n"); 
  481. #endif
  482.     return;
  483.   }
  484.  
  485.   X11ActualWindows[X11DrawablesMap[win]].width=width;
  486.   X11ActualWindows[X11DrawablesMap[win]].height=height;
  487.   w=X11DrawablesWindows[X11DrawablesMap[win]];
  488.   if(!w) return 0;
  489.   if(temprp.BitMap) free_bitmap(temprp.BitMap);
  490.   else InitRastPort(&temprp);
  491.   temprp.BitMap=alloc_bitmap((width+16),1,DG.nDisplayDepth,BMF_CLEAR);
  492.   ChangeWindowBox(w,w->LeftEdge,w->TopEdge,width+w->BorderLeft+w->BorderRight,
  493.           height+w->BorderTop+w->BorderBottom);
  494.  
  495.   SetRast(w->RPort,(UBYTE)X11DrawablesBackground[win]);
  496.   return(0);
  497. }
  498.  
  499. Status XGetWindowAttributes(display, win, window_attributes_return)
  500.      Display *display;
  501.      Window win;
  502.      XWindowAttributes *window_attributes_return;
  503. {/*    File 'image_f_io.o'*/
  504.   struct Window *w;
  505. #ifdef DEBUGXEMUL_ENTRY
  506.   printf("XGetWindowAttributes\n");
  507. #endif
  508.   if(X11Drawables[win]==X11SUBWINDOW) return;
  509.   if(X11Drawables[win]==X11BITMAP) {
  510. #ifdef DEBUGX11BITMAP
  511.     printf("XGetWindowAttributes to bitmap?\n"); 
  512. #endif
  513.     return;
  514.   }
  515.   if(X11Drawables[win]==X11WINDOW)
  516.     w=X11DrawablesWindows[X11DrawablesMap[win]];
  517.   else if(X11Drawables[win]==X11MUI)
  518.     w=_window(X11DrawablesMUI[X11DrawablesMap[win]]);
  519.  
  520.   if(!w) return 0;
  521.   window_attributes_return->x=w->LeftEdge+w->BorderLeft;
  522.   window_attributes_return->y=w->TopEdge+w->BorderTop;
  523.   window_attributes_return->depth=w->RPort->BitMap->Depth;
  524.   window_attributes_return->width=w->Width-(w->BorderLeft+w->BorderRight);
  525.   window_attributes_return->height=w->Height-(w->BorderTop+w->BorderBottom);
  526.   window_attributes_return->border_width=0;
  527.   return(1);
  528. }
  529.  
  530. XConfigureWindow(display, w, value_mask, values)
  531.      Display *display;
  532.      Window w;
  533.      unsigned int value_mask;
  534.      XWindowChanges *values;
  535. {
  536.   struct Window *win;
  537. #ifdef DEBUGXEMUL_ENTRY
  538.   printf("ConfigureWindow %d\n",w);
  539. #endif
  540.  
  541.   if(X11Drawables[w]==X11SUBWINDOW){
  542.     int child=X11DrawablesSubWindows[X11DrawablesMap[w]];
  543.     X11DrawablesChildren[child].x=values->x;
  544.     X11DrawablesChildren[child].y=values->y;
  545.     X11DrawablesChildren[child].width=values->width;
  546.     X11DrawablesChildren[child].height=values->height;
  547.     X11AddConfigure(w,NULL);
  548.     X11AddExpose(w,NULL);
  549.     return;
  550.   }
  551.   if(X11Drawables[w]==X11BITMAP){
  552.     return;
  553.   }
  554.   if(value_mask&CWX) X11ActualWindows[X11DrawablesMap[w]].x=values->x;
  555.   if(value_mask&CWY) X11ActualWindows[X11DrawablesMap[w]].y=values->y;
  556.   if(value_mask&CWWidth) X11ActualWindows[X11DrawablesMap[w]].width=values->width;
  557.   if(value_mask&CWHeight) X11ActualWindows[X11DrawablesMap[w]].height=values->height;
  558.   win=X11DrawablesWindows[X11DrawablesMap[w]];
  559.   if(!win) return 0;
  560.   ChangeWindowBox(win,
  561.           X11ActualWindows[X11DrawablesMap[w]].x,
  562.           X11ActualWindows[X11DrawablesMap[w]].y,
  563.           X11ActualWindows[X11DrawablesMap[w]].width+win->BorderLeft+win->BorderRight,
  564.           X11ActualWindows[X11DrawablesMap[w]].height+win->BorderTop+win->BorderBottom);
  565.  
  566.   X11AddConfigure(w,win);
  567.   X11AddExpose(w,win);
  568.   return(0);
  569. }
  570.  
  571. XSetWindowBorder(display, w, border_pixel)
  572.      Display *display;
  573.      Window w;
  574.      unsigned long border_pixel;
  575. {
  576. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  577.   printf("WARNING: XSetWindowBorder\n");
  578. #endif
  579.   return 0;
  580. }
  581.  
  582. XClearArea(display, win, x, y, width, height, exposures)
  583.      Display *display;
  584.      Window win;
  585.      int x, y;
  586.      unsigned int width, height;
  587.      Bool exposures;
  588. {
  589.   int endx,endy;
  590.   int oldfg,olddrmd;
  591. #ifdef DEBUGXEMUL_ENTRY
  592.   printf("XClearArea\n");
  593. #endif
  594.   if(win!=prevwin) if(!(drp=setup_win(win))) return;
  595.   endx=x+width-1;
  596.   endy=y+height-1;
  597.   oldfg=drp->FgPen;
  598.   olddrmd=drp->DrawMode;
  599.   if(X11Drawables[win]==X11MUI){
  600.     Object *w=X11DrawablesMUI[X11DrawablesMap[win]];
  601.     SetAPen(_rp(w),_dri(w)->dri_Pens[BACKGROUNDPEN]);
  602.   }
  603.   else SetAPen(drp,X11DrawablesBackground[win]);
  604.   SetDrMd(drp,JAM1);
  605.   if(width==0) endx=X_right;
  606.   if(height==0) endy=X_bottom;
  607.   RectFill(drp,X_relx+x,X_rely+y,X_relx+endx,X_rely+endy);
  608.   drp->DrawMode=olddrmd;
  609.   drp->FgPen=oldfg;
  610.   return(0);
  611. }
  612.  
  613. extern int XSetClipMask(Display *,GC,Pixmap);
  614.  
  615. XClearWindow(display, w)
  616.      Display *display;
  617.      Window w;
  618. {
  619.   extern int usewb,wbapp,adjx,adjy;
  620.   struct Window *win;
  621. #ifdef DEBUGXEMUL_ENTRY
  622.   printf("XClearWindow\n");
  623. #endif
  624.   if(w!=prevwin) if(!(drp=setup_win(w))) return;
  625.   if(X11Drawables[w]==X11SUBWINDOW) { /* subwindow */
  626.     int child=X11DrawablesSubWindows[X11DrawablesMap[w]];
  627.     clear_subwin(w,1,X11DrawablesBackground[child]);
  628.   }else if(X11Drawables[w]==X11WINDOW) {
  629.     int i;
  630.     win=Agetwin(w);
  631.     prevwin=-1;
  632.     if(!win) return;
  633.     if(usewb||wbapp)
  634.       clip_begin(win->LeftEdge+win->BorderLeft,win->TopEdge+win->BorderTop,win->Width-adjx,win->Height-adjy);
  635.     else
  636.       clip_begin(win->LeftEdge,win->TopEdge,win->Width,win->Height);
  637.     /* and exclude all subwins */
  638.     for(i=1;i<=DG.nNumChildren;i++)
  639.       if(!X11DrawablesChildren[i].deleted&&X11DrawablesChildren[i].parent==w)
  640.     clip_exclude(X11DrawablesChildren[i].x,X11DrawablesChildren[i].y,X11DrawablesChildren[i].width-1,X11DrawablesChildren[i].height-1);
  641.     clip_end(win);
  642.     SetAPen(win->RPort,(UBYTE)X11DrawablesBackground[w]);
  643.     SetBPen(win->RPort,(UBYTE)0);
  644.     SetDrMd(win->RPort,JAM1);
  645.     RectFill(win->RPort,win->LeftEdge,win->TopEdge,win->Width,win->Height);
  646.     XSetClipMask(display,amiga_gc,None);
  647.     prevwin=-1;
  648.   } else if(X11Drawables[w]==X11MUI) {
  649.     Object *mwin=X11DrawablesMUI[X11DrawablesMap[w]];
  650.     if(!isopen(mwin)) return;
  651.     SetAPen(_rp(mwin),_dri(mwin)->dri_Pens[BACKGROUNDPEN]);
  652.     SetDrMd(_rp(mwin),JAM1);
  653.     RectFill(_rp(mwin),_mleft(mwin),_mtop(mwin),_mright(mwin),_mbottom(mwin));
  654.   } else if(X11Drawables[w]==X11BITMAP) {
  655.     /* X11ClearArea */
  656.     XClearArea(display,w,0,0,
  657.          X11DrawablesBitmaps[X11DrawablesMap[w]].width,
  658.          X11DrawablesBitmaps[X11DrawablesMap[w]].height,0);
  659.   }
  660.   prevgc=(GC)-1;
  661. }
  662.  
  663. XDestroySubwindows(display, w)
  664.      Display *display;
  665.      Window w;
  666. {/*      File 'x11perf.o'*/
  667.   int i;
  668. #if (DEBUGXEMUL_ENTRY)
  669.   printf("XDestroySubwindows\n");
  670. #endif
  671.  
  672.   for(i=0;i<DG.nNumChildren;i++)
  673.     if(X11DrawablesChildren[i].parent==w)
  674.       XDestroyWindow(display,X11DrawablesChildren[i].id);
  675.   return(0);
  676. }
  677.  
  678. XSetScreenSaver(display, timeout, interval,
  679.         prefer_blanking, allow_exposures)
  680.      Display *display;
  681.      int timeout, interval;
  682.      int prefer_blanking;
  683.      int allow_exposures;
  684. {/*         File 'x11perf.o'*/
  685. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  686.   printf("WARNING: XSetScreenSaver\n");
  687. #endif
  688.   return(0);
  689. }
  690.  
  691. XForceScreenSaver(display, mode)
  692.      Display *display;
  693.      int mode;
  694. {/*       File 'x11perf.o'*/
  695. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  696. /*  printf("WARNING: XForceScreenSaver\n");*/
  697. #endif
  698.   return(0);
  699. }
  700.  
  701. XMapSubwindows(display, w)
  702.      Display *display;
  703.      Window w;
  704. {
  705.   int i;
  706. #if (DEBUGXEMUL_ENTRY)
  707.   printf("XMapSubwindows %d\n",w);
  708. #endif
  709.   
  710.   for(i=0;i<DG.nNumChildren;i++)
  711.     if(X11DrawablesChildren[i].parent==w)
  712.       XMapWindow(display,X11DrawablesChildren[i].id);
  713.   return(0);
  714. }
  715.  
  716. /*int XSynchronize(Display *d,Bool b){/*            File 'x11perf.o'*/
  717. #ifdef DEBUGXEMUL_ENTRY
  718.   printf("XSynchronize\n");
  719. #endif
  720.   return(0);
  721. }*/
  722.  
  723. XChangeProperty(display, w, property, type, format, mode,
  724.         data, nelements)
  725.      Display *display;
  726.      Window w;
  727.      Atom property, type;
  728.      int format;
  729.      int mode;
  730.      unsigned char *data;
  731.      int nelements;
  732. {/*         File 'do_simple.o'*/
  733. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  734.   printf("WARNING: XChangeProperty\n");
  735. #endif
  736.   return(0);
  737. }
  738.  
  739. XMoveWindow(display, win, x, y)
  740.      Display *display;
  741.      Window win;
  742.      int x, y;
  743. {/*             File 'do_movewin.o'*/
  744.   int i;
  745. #ifdef DEBUGXEMUL_ENTRY
  746.   printf("XMoveWindow\n");
  747. #endif
  748.   if(X11Drawables[win]==X11SUBWINDOW){ /* subwindow */
  749.     int w=X11DrawablesSubWindows[X11DrawablesMap[win]];
  750.     X11DrawablesChildren[w].x=x;
  751.     X11DrawablesChildren[w].y=y;
  752.     X11AddExpose(win,NULL);
  753.   } else {
  754.     X11ActualWindows[X11DrawablesMap[win]].x=x;
  755.     X11ActualWindows[X11DrawablesMap[win]].y=y;
  756.     X11AddExpose(win,X11DrawablesWindows[X11DrawablesMap[win]]);
  757.   }
  758.   for(i=0;i<DG.nNumChildren;i++)
  759.     if(X11DrawablesChildren[i].parent==win){
  760.       X11AddExpose(win,NULL);
  761.     }
  762.   
  763.   return(0);
  764. }
  765.  
  766. XGetScreenSaver(display, timeout_return, interval_return,
  767.         prefer_blanking_return, allow_exposures_return)
  768.      Display *display;
  769.      int *timeout_return, *interval_return;
  770.      int *prefer_blanking_return;
  771.      int *allow_exposures_return;
  772. {/*         File 'x11perf.o'*/
  773. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  774.   printf("WARNING: XGetScreenSaver\n");
  775. #endif
  776.   return(0);
  777. }
  778.  
  779. char *XDisplayName(char *name){/*            File 'x11perf.o'*/
  780. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  781.   printf("WARNING: XDisplayName\n");
  782. #endif
  783.   return(0);
  784. }
  785.  
  786. Status XQueryBestSize(display, class, which_screen, width,
  787.               height, width_return, height_return)
  788.      Display *display;
  789.      int class;
  790.      Drawable which_screen;
  791.      unsigned int width, height;
  792.      unsigned int *width_return, *height_return;
  793. {/*          File 'x11perf.o'*/
  794. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  795.   printf("WARNING: XQueryBestSize\n");
  796. #endif
  797.   return(0);
  798. }
  799.  
  800. XCirculateSubwindows(display, w, direction)
  801.      Display *display;
  802.      Window w;
  803.      int direction;
  804. {/*    File 'do_movewin.o'*/
  805. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  806.   printf("WARNING: XCirculateSubwindows\n");
  807. #endif
  808.   return(0);
  809. }
  810.  
  811. int XWMGeometry(display, screen, user_geom, def_geom, bwidth_return,
  812.         hints, x_return, y_return, width_return, height_return,
  813.         gravity_return)
  814.      Display *display;
  815.      int screen;
  816.      char *user_geom;
  817.      char *def_geom;
  818.      unsigned int bwidth_return;
  819.      XSizeHints *hints;
  820.      int *x_return, *y_return;
  821.      int *width_return, *height_return;
  822.      int *gravity_return;
  823. {/*             File 'magick/libMagick.lib' */
  824.   XWindowAttributes xattr;
  825. #ifdef DEBUGXEMUL_ENTRY
  826.   printf("XWMGeometry\n");
  827. #endif
  828.   XGetWindowAttributes(display,RootWindow(display,screen),&xattr);
  829.   *x_return=xattr.x;
  830.   *y_return=xattr.y;
  831.   *width_return=xattr.width;
  832.   *height_return=xattr.height;
  833.   *gravity_return=0;
  834.   return(0);
  835. }
  836.  
  837. void XSetWMProperties(display, w, window_name, icon_name, argv, argc,
  838.               normal_hints, wm_hints, class_hints)
  839.      Display *display;
  840.      Window w;
  841.      XTextProperty *window_name;
  842.      XTextProperty *icon_name;
  843.      char **argv;
  844.      int argc;
  845.      XSizeHints *normal_hints;
  846.      XWMHints *wm_hints;
  847.      XClassHint *class_hints;
  848. {/*        File 'magick/libMagick.lib' */
  849. #ifdef DEBUGXEMUL_ENTRY
  850.   printf("XSetWMProperties [%d,%d]\n",normal_hints->width,normal_hints->height);
  851. #endif
  852.   X11ActualWindows[X11DrawablesMap[w]].name=window_name->value;
  853.   if(normal_hints){
  854.     X11ActualWindows[X11DrawablesMap[w]].x=normal_hints->x;
  855.     X11ActualWindows[X11DrawablesMap[w]].y=normal_hints->y;
  856.   }
  857.   return;
  858. }
  859.  
  860. Status XWithdrawWindow(display, w, screen_number)
  861.      Display *display;
  862.      Window w;
  863.      int screen_number;
  864. {/*         File 'magick/libMagick.lib' */
  865. #ifdef DEBUGXEMUL_ENTRY
  866.   printf("XWithdrawWindow\n");
  867. #endif
  868.   XUnmapWindow(display,w);
  869.   return(0);
  870. }
  871.  
  872. void XSetWMName(display,w,text_prop)
  873.      Display *display;
  874.      Window w;
  875.      XTextProperty *text_prop;
  876. {/*              File 'magick/libMagick.lib' */
  877. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  878.   printf("WARNING: XSetWMName\n");
  879. #endif
  880.   X11ActualWindows[X11DrawablesMap[w]].name=text_prop->value;
  881.   return;
  882. }
  883.  
  884. XGetWMName(display,w,text_prop_return)
  885.      Display *display;
  886.      Window w;
  887.      XTextProperty *text_prop_return;
  888. {/*              File 'magick/libMagick.lib' */
  889. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  890.   printf("WARNING: XGetWMName\n");
  891. #endif
  892.   text_prop_return->value=X11ActualWindows[X11DrawablesMap[w]].name;
  893.   return(0);
  894. }
  895.  
  896. Status XReconfigureWMWindow(display, w, screen_number, value_mask, values)
  897.      Display *display;
  898.      Window w;
  899.      int screen_number;
  900.      unsigned int value_mask;
  901.      XWindowChanges *values;
  902. {/*    File 'magick/libMagick.lib' */
  903.   _ActualWindow *aw;
  904.   XWindowChanges xwc;
  905. #ifdef DEBUGXEMUL_ENTRY
  906.   printf("XReconfigureWMWindow\n");
  907. #endif
  908.   if(X11Drawables[w]!=X11WINDOW) return; /* not window */
  909.   aw=&X11ActualWindows[X11DrawablesMap[w]];
  910.   if(value_mask&CWX) aw->x=values->x;
  911.   if(value_mask&CWY) aw->y=values->y;
  912.   if(value_mask&CWWidth) aw->width=values->width;
  913.   if(value_mask&CWHeight) aw->height=values->height;
  914.   if (aw->x+aw->width>wb->Width){
  915.     aw->x=wb->Width-aw->width;
  916.   }
  917.   if (aw->y+aw->height>wb->Height){
  918.     aw->y=wb->Height-aw->height;
  919.   }
  920.   xwc.x=aw->x; xwc.y=aw->y; xwc.width=aw->width; xwc.height=aw->height;
  921.   if(X11ActualWindows[X11DrawablesMap[w]].mapped)
  922.     XConfigureWindow(display,w,CWX|CWY|CWWidth|CWHeight,&xwc);
  923.   return(0);
  924. }
  925.  
  926. XWMHints *XAllocWMHints()
  927. {/*           File 'animate.o' */
  928.   XWMHints *xwmh=malloc(sizeof(XWMHints));
  929. #ifdef DEBUGXEMUL
  930.   printf("XAllocWMHints\n");
  931. #endif
  932.   List_AddEntry(pMemoryList,(void*)xwmh);
  933.   if(!xwmh) X11resource_exit(WINDOW4);
  934.   return(xwmh);
  935. }
  936.  
  937. Window XDefaultRootWindow(Display *d){/*      File 'w_util.o'*/
  938. #ifdef DEBUGXEMUL_ENTRY
  939.   printf("XDefaultRootWindow\n");
  940. #endif
  941.   return(RootWindowOfScreen(DefaultScreenOfDisplay(d)));
  942. }
  943.  
  944. XMoveResizeWindow(display, w, x, y, width, height)
  945.      Display *display;
  946.      Window w;
  947.      int x, y;
  948.      unsigned int width, height;
  949. {/*       File 'xvscrl.o' */
  950. #ifdef DEBUGXEMUL_ENTRY
  951.   printf("XMoveResizeWindow\n");
  952. #endif
  953.   XMoveWindow(display,w,x,y);
  954.   XResizeWindow(display,w,width,height);
  955.   return(0);
  956. }
  957.  
  958. Status XQueryTree(display, w, root_return, parent_return,
  959.           children_return, nchildren_return)
  960.      Display *display;
  961.      Window w;
  962.      Window *root_return;
  963.      Window *parent_return;
  964.      Window **children_return;
  965.      unsigned int *nchildren_return;
  966. {
  967.   int i;
  968.   int childrens=0;
  969. #ifdef DEBUGXEMUL_ENTRY
  970.   printf("XQueryTree\n");
  971. #endif
  972.  
  973.   *children_return=NULL;
  974.   *nchildren_return=0;
  975.   *root_return=DefaultRootWindow(display);
  976.   if( w==ROOTID||w==1 )
  977.     *parent_return=ROOTID;
  978. /*
  979.     return 0;
  980. */
  981.   else
  982.     *parent_return=X11findparent(w);
  983. /*
  984.   if(w==*parent_return)
  985.     *parent_return=ROOTID;
  986. */
  987.   for(i=1;i<=DG.nNumChildren;i++)
  988.     if(!X11DrawablesChildren[i].deleted&&X11DrawablesChildren[i].parent==w)
  989.       childrens++;
  990.  
  991.   *nchildren_return=childrens;
  992.   if(childrens){
  993.     Window *aWins;
  994.     int n=0;
  995.     aWins=(Window*)malloc(sizeof(Window)*(childrens));
  996.     List_AddEntry(pMemoryList,(void*)aWins);
  997.     for(i=1;i<=DG.nNumChildren;i++)
  998.       if(!X11DrawablesChildren[i].deleted&&X11DrawablesChildren[i].parent==w)
  999.     aWins[n++]=(Window)X11DrawablesChildren[i].id;
  1000.     *children_return=aWins;
  1001.   }
  1002.   if(!childrens && w==ROOTID){
  1003.     Window *aWins;
  1004.     int n=0;
  1005.     aWins=(Window*)malloc(sizeof(Window)*(X11NumDrawablesWindows));
  1006.     List_AddEntry(pMemoryList,(void*)aWins);
  1007.     for(i=0;i<X11NumDrawablesWindows;i++)
  1008.       if(X11ActualWindows[i].parent==ROOTID){
  1009.     aWins[n++]=(Window)X11ActualWindows[i].win;
  1010.       }
  1011.     *children_return=aWins;
  1012.   }
  1013.   return(1);
  1014. }
  1015.  
  1016. Status XGetGeometry(display, drawable, root_return, x_return,y_return,
  1017.             width_return, height_return, border_width_return,depth_return)
  1018.      Display *display;
  1019.      Drawable drawable;
  1020.      Window *root_return;
  1021.      int *x_return, *y_return;
  1022.      unsigned int *width_return, *height_return;
  1023.      unsigned int *border_width_return;
  1024.      unsigned int *depth_return;
  1025. {/*            File 'xvgrab.o' */
  1026. #ifdef DEBUGXEMUL_ENTRY
  1027.   printf("XGetGeometry\n");
  1028. #endif
  1029.   if(border_width_return) *border_width_return=1;
  1030.   if(X11Drawables[drawable]==X11WINDOW){
  1031.     struct Window *win=X11DrawablesWindows[X11DrawablesMap[drawable]];
  1032.     if(!win) return 0;
  1033.     *width_return=win->Width-(win->BorderLeft+win->BorderRight);;
  1034.     *height_return=win->Height-(win->BorderTop+win->BorderBottom);
  1035.     *depth_return=win->RPort->BitMap->Depth;
  1036.     *x_return=win->LeftEdge;
  1037.     *y_return=win->TopEdge;
  1038.   } else if(X11Drawables[drawable]==X11SUBWINDOW){
  1039.     int child=X11DrawablesSubWindows[X11DrawablesMap[drawable]];
  1040.     int parent=X11findparent(drawable);
  1041.     struct Window *w=X11DrawablesWindows[X11DrawablesMap[parent]];
  1042.  
  1043.     *width_return=X11DrawablesChildren[child].width;
  1044.     *height_return=X11DrawablesChildren[child].height;
  1045.     *x_return=w->BorderLeft+X11DrawablesChildren[child].x;
  1046.     *y_return=w->BorderTop+X11DrawablesChildren[child].y;
  1047.   } else if(X11Drawables[drawable]==X11BITMAP){
  1048. /*
  1049.     struct BitMap *bm=X11DrawablesBitmaps[X11DrawablesMap[drawable]].pBitMap;
  1050. */
  1051.     *x_return=0;
  1052.     *y_return=0;
  1053.     *width_return=X11DrawablesBitmaps[X11DrawablesMap[drawable]].width;
  1054.     *height_return=X11DrawablesBitmaps[X11DrawablesMap[drawable]].height;
  1055.     *border_width_return=0;
  1056.     *depth_return=X11DrawablesBitmaps[X11DrawablesMap[drawable]].depth;
  1057.   } else if(X11Drawables[drawable]==X11MUI){
  1058.   } 
  1059.   return(TRUE);
  1060. }
  1061.  
  1062. XRaiseWindow(display, w)
  1063.      Display *display;
  1064.      Window w;
  1065. {/*            File 'xvtext.o' */
  1066.   XEvent event;
  1067. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1068.   printf("WARNING: XRaiseWindow\n");
  1069. #endif
  1070.   event.type=ConfigureNotify;
  1071.   event.xconfigure.window=w;
  1072.   if (X11Drawables[w]==X11SUBWINDOW) {
  1073.     event.xconfigure.width=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[w]]].width;
  1074.     event.xconfigure.height=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[w]]].height;
  1075.     event.xconfigure.x=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[w]]].x;
  1076.     event.xconfigure.y=X11DrawablesChildren[X11DrawablesSubWindows[X11DrawablesMap[w]]].y;
  1077.   } else {
  1078.     event.xconfigure.width=X11ActualWindows[X11DrawablesMap[w]].width;
  1079.     event.xconfigure.height=X11ActualWindows[X11DrawablesMap[w]].height;
  1080.     event.xconfigure.x=X11ActualWindows[X11DrawablesMap[w]].x;
  1081.     event.xconfigure.y=X11ActualWindows[X11DrawablesMap[w]].y;
  1082.     WindowToFront(X11DrawablesWindows[X11DrawablesMap[w]]);
  1083.   }
  1084.   X11NewInternalXEvent(&event,sizeof(XConfigureEvent));
  1085.  
  1086.   return(0);
  1087. }
  1088.  
  1089. shift[]={13,10,7,12,9,6,11,8};
  1090.  
  1091. __stdargs unsigned long  XGet_pixel(struct _XImage*,int,int);
  1092.  
  1093. __stdargs unsigned long  XGet_pixel(struct _XImage *xim,int x,int y){
  1094.   int bit;
  1095.   unsigned char *byte;
  1096.   if(xim->bitmap_bit_order==LSBFirst){
  1097.     switch(xim->depth){
  1098.     case 1:
  1099.       byte=(xim->data+y*xim->bytes_per_line+(x>>3));
  1100.       bit=(*byte)&((128>>(x%8)));
  1101.       break;
  1102.     case 3: {
  1103.       short *byte;
  1104.       int  pos=(int)((x%8)/xim->bits_per_pixel)+(int)(x/8)*3;
  1105.       byte=(short*)(xim->data+y*xim->bytes_per_line+pos);
  1106.       bit=*byte&(7<<shift[x % 8]);
  1107.       } break;
  1108.     case 4:
  1109.       byte=xim->data+y*xim->bytes_per_line+(x>>1);
  1110.       bit=*byte&(15<<((x%2)*4));
  1111.     case 8:
  1112.       byte=(xim->data+y*xim->bytes_per_line+x);
  1113.       bit=*byte;
  1114.       break;
  1115.     }
  1116.  
  1117. /*
  1118.     if(xim->depth==1){
  1119.       int byte=*(xim->data+y*xim->bytes_per_line+(x>>3));
  1120.       bit=byte&(1<<(x%8));
  1121.     }
  1122.     else{
  1123.       int byte=*(xim->data+y*xim->bytes_per_line+x);
  1124.       bit=byte;
  1125.     }
  1126. */
  1127.   }
  1128.   else{
  1129.     switch(xim->depth){
  1130.     case 1:
  1131.       byte=(xim->data+y*xim->bytes_per_line+(x>>3));
  1132.       bit=(*byte)&((128>>(x%8)));
  1133.       break;
  1134.     case 3: {
  1135.       short *byte;
  1136.       int  pos=(int)((x%8)/xim->bits_per_pixel)+(int)(x/8)*3;
  1137.       byte=(short*)(xim->data+y*xim->bytes_per_line+pos);
  1138.       bit=*byte&(7<<shift[x % 8]);
  1139.       } break;
  1140.     case 4:
  1141.       byte=xim->data+y*xim->bytes_per_line+(x>>1);
  1142.       bit=*byte&(15<<((x%2)*4));
  1143.       break;
  1144.     case 8:
  1145.       byte=(xim->data+y*xim->bytes_per_line+x);
  1146.       bit=*byte;
  1147.       break;
  1148.     }
  1149.  
  1150. /*
  1151.     if(xim->depth==1){
  1152.       int byte=*(xim->data+y*xim->bytes_per_line+(x>>3));
  1153.       bit=byte&(128>>(x%8));
  1154.     }
  1155.     else{
  1156.       int byte=*(xim->data+y*xim->bytes_per_line+x);
  1157.       bit=byte;
  1158.     }
  1159. */
  1160.   }
  1161.   return((unsigned long)bit);
  1162. }
  1163.  
  1164. __stdargs int XPut_Pixel(XImage *xim, int x, int y, unsigned long pixel);
  1165.  
  1166. __stdargs int XPut_Pixel(XImage *xim, int x, int y, unsigned long pixel)
  1167. {
  1168.   unsigned char *byte;
  1169.   if(xim->bitmap_bit_order==LSBFirst){
  1170.     switch(xim->depth){
  1171.     case 1:
  1172.       byte=(xim->data+y*xim->bytes_per_line+(x>>3));
  1173.       *byte=(*byte)|((1<<(x%8))*pixel);
  1174.       break;
  1175.     case 3:{
  1176.       short *byte;
  1177.       int  pos=(int)((x%8)/xim->bits_per_pixel)+(int)(x/8)*3;
  1178.       byte=(short*)(xim->data+y*xim->bytes_per_line+pos);
  1179.       *byte=*byte|(pixel<<shift[x % 8]);
  1180.       } break;
  1181.     case 4:
  1182.       byte=xim->data+y*xim->bytes_per_line+(x>>1);
  1183.       *byte=*byte|(pixel<<((x%2)*4));
  1184.       break;
  1185.     case 5:
  1186.       break;
  1187.     case 6:
  1188.       break;
  1189.     case 7:
  1190.       break;
  1191.     case 8:
  1192.       byte=(xim->data+y*xim->bytes_per_line+x);
  1193.       *byte=pixel;
  1194.       break;
  1195.     }
  1196.   } else{
  1197.     switch(xim->depth){
  1198.     case 1:
  1199.       byte=(xim->data+y*xim->bytes_per_line+(x>>3));
  1200.       *byte=(*byte)|((128>>(x%8))*pixel);
  1201.       break;
  1202.     case 3: {
  1203.       short *byte;
  1204.       int  pos=(int)((x%8)/xim->bits_per_pixel)+(int)(x/8)*3;
  1205.       byte=(short*)(xim->data+y*xim->bytes_per_line+pos);
  1206.       *byte=*byte|(pixel<<shift[x % 8]);
  1207.       } break;
  1208.     case 4:
  1209.       byte=xim->data+y*xim->bytes_per_line+(x>>1);
  1210.       *byte=*byte|(pixel<<((x%2)*4));
  1211.       break;
  1212.     case 8:
  1213.       byte=(xim->data+y*xim->bytes_per_line+x);
  1214.       *byte=pixel;
  1215.       break;
  1216.     }
  1217.   }
  1218.   return((int)*byte);
  1219. }
  1220.  
  1221. XSetWindowBackgroundPixmap(display, w, background_pixmap)
  1222.      Display *display;
  1223.      Window w;
  1224.      Pixmap background_pixmap;
  1225. {
  1226. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1227.   printf("WARNING: XSetWindowBackgroundPixmap\n");
  1228. #endif
  1229.   return(0);
  1230. }
  1231.